package avicit.bdp.dds.server.entity;

import static avicit.bdp.dds.common.Constants.UNDERLINE;

/**
 *  task priority info
 */
public class TaskPriority {

    /**
     * processInstancePriority
     */
    private int processInstancePriority;

    /**
     * processInstanceId
     */
    private String processInstanceId;

    /**
     * taskInstancePriority
     */
    private int taskInstancePriority;

    /**
     * taskId
     */
    private String taskId;

    /**
     * groupName
     */
    private String groupName;

    /**
     *   ${processInstancePriority}_${processInstanceId}_${taskInstancePriority}_${taskId}_${groupName}
     */
    private String taskPriorityInfo;

    public TaskPriority(){}

    public TaskPriority(int processInstancePriority,
                        String processInstanceId,
                        int taskInstancePriority,
                        String taskId, String groupName) {
        this.processInstancePriority = processInstancePriority;
        this.processInstanceId = processInstanceId;
        this.taskInstancePriority = taskInstancePriority;
        this.taskId = taskId;
        this.groupName = groupName;
        this.taskPriorityInfo = this.processInstancePriority +
                UNDERLINE +
                this.processInstanceId +
                UNDERLINE +
                this.taskInstancePriority +
                UNDERLINE +
                this.taskId +
                UNDERLINE +
                this.groupName;
    }

    public int getProcessInstancePriority() {
        return processInstancePriority;
    }

    public void setProcessInstancePriority(int processInstancePriority) {
        this.processInstancePriority = processInstancePriority;
    }

    public String getProcessInstanceId() {
        return processInstanceId;
    }

    public void setProcessInstanceId(String processInstanceId) {
        this.processInstanceId = processInstanceId;
    }

    public int getTaskInstancePriority() {
        return taskInstancePriority;
    }

    public void setTaskInstancePriority(int taskInstancePriority) {
        this.taskInstancePriority = taskInstancePriority;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public String getTaskPriorityInfo() {
        return taskPriorityInfo;
    }

    public void setTaskPriorityInfo(String taskPriorityInfo) {
        this.taskPriorityInfo = taskPriorityInfo;
    }

    /**
     * taskPriorityInfo convert taskPriority
     *
     * @param taskPriorityInfo taskPriorityInfo
     * @return TaskPriority
     */
    public static TaskPriority of(String taskPriorityInfo){
        String[] parts = taskPriorityInfo.split(UNDERLINE);

        if (parts.length != 5) {
            throw new IllegalArgumentException(String.format("TaskPriority : %s illegal.", taskPriorityInfo));
        }
        TaskPriority taskPriority = new TaskPriority(
                Integer.parseInt(parts[0]),
                parts[1],
                Integer.parseInt(parts[2]),
                parts[3],
                parts[4]);
        return taskPriority;
    }
}
